package com.idsmanager.zdh.service.business.api;

import com.idsmanager.commons.web.WebUtils;
import com.idsmanager.commons.web.context.BeanProvider;
import com.idsmanager.oauth.domain.security.SecurityUtils;
import com.idsmanager.oauth.domain.security.User;
import com.idsmanager.oauth.domain.security.UserRepository;
import com.idsmanager.zdh.infrastructure.APIError;
import com.idsmanager.zdh.service.dto.api.UserApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RestDelUserByGuidRemover {

    private static final Logger LOG = LoggerFactory.getLogger(RestDelUserByGuidRemover.class);

    private transient UserRepository repository = BeanProvider.getBean(UserRepository.class);

    public UserApiResult remove(String guid) {
        final User user = repository.findByGuid(guid);
        if(user == null){
            LOG.warn("{}|Not found user by guid:{}", WebUtils.getIp(),guid);
            return new UserApiResult(APIError.PARAM_ERROR,"未知的guid："+guid);
        }
        repository.removeUser(user);
        LOG.debug("{}|Removed User:{} ", SecurityUtils.username(),user);
        return new UserApiResult();
    }

}
